package com.example.travelservlet.focus.service;

import com.example.travelservlet.entity.*;
import com.example.travelservlet.focus.dao.UserFocusMapper;
import com.example.travelservlet.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author yxj
 * @date 2023/5/24 8:21
 */
@Service
public class UserFocusService {

    @Autowired
    private UserFocusMapper userFocusMapper;

    public User findById(String userId) {
        User user = userFocusMapper.findUserById(userId);
        return user;
    }

    public List<String> findFocusId(String userId) {
        return userFocusMapper.findFocusUserByUserId(userId);
    }

    public List<User> findFocusUserByUserId(String userId) {
        List<String> focusUserIdList = userFocusMapper.findFocusUserByUserId(userId);
        List<User> focusUserByUserId = new ArrayList<>();
        for (int i = 0; i < focusUserIdList.size(); i++) {
            User user = userFocusMapper.findUserById(focusUserIdList.get(i));
            focusUserByUserId.add(user);
        }
        return focusUserByUserId;
    }

    public List<User> findSome(String userId, String text) {
        List<String> focusUserIdList = userFocusMapper.findFocusUserByUserId(userId);
        List<User> focusUserByUserId = new ArrayList<>();
        for (int i = 0; i < focusUserIdList.size(); i++) {
            User user = userFocusMapper.findSome(focusUserIdList.get(i), text);
            if (user != null) {
                focusUserByUserId.add(user);
            }
        }
        return focusUserByUserId;
    }

    public List<User> findSomeFans(String userId, String text) {
        List<String> focusUserIdList = userFocusMapper.findFansByFocusId(userId);
        List<User> focusUserByUserId = new ArrayList<>();
        for (int i = 0; i < focusUserIdList.size(); i++) {
            User user = userFocusMapper.findSome(focusUserIdList.get(i), text);
            if (user != null) {
                focusUserByUserId.add(user);
            }
        }
        return focusUserByUserId;
    }

    public List<User> findFansById(String userId) {
        List<String> focusUserIdList = userFocusMapper.findFansByFocusId(userId);
        List<User> focusUserByUserId = new ArrayList<>();
        for (int i = 0; i < focusUserIdList.size(); i++) {
            User user = userFocusMapper.findUserById(focusUserIdList.get(i));
            focusUserByUserId.add(user);
        }
        return focusUserByUserId;
    }


    public Integer deleteFocus(String userId, String focusUserId) {
        Integer integer = userFocusMapper.delectFocusByIdAndFocusUserId(userId, focusUserId);
        return integer;
    }


    public Integer addFocus(String userId, String focusUserId) {
        Focus focus = new Focus();
        focus.setFocusUserId(focusUserId);
        focus.setUserId(userId);
        Integer integer = userFocusMapper.addFocus(focus);
        return integer;
    }
}
